package com.ruoyi.product.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductSpecTemplateRelation;
import com.ruoyi.product.service.IProductSpecTemplateRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模板与规格属性的关联Controller
 *
 * @author liuhuizhong
 * @date 2025-08-07
 */
@RestController
@RequestMapping("/product/productSpecTemplateRelation")
public class ProductSpecTemplateRelationController extends BaseController {
    @Autowired
    private IProductSpecTemplateRelationService productSpecTemplateRelationService;

    /**
     * 查询模板与规格属性的关联列表
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplateRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductSpecTemplateRelation productSpecTemplateRelation) {
        startPage();
        List<ProductSpecTemplateRelation> list = productSpecTemplateRelationService.selectProductSpecTemplateRelationList(productSpecTemplateRelation);
        return getDataTable(list);
    }

    /**
     * 导出模板与规格属性的关联列表
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplateRelation:export')")
    @Log(title = "模板与规格属性的关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductSpecTemplateRelation productSpecTemplateRelation) {
        List<ProductSpecTemplateRelation> list = productSpecTemplateRelationService.selectProductSpecTemplateRelationList(productSpecTemplateRelation);
        ExcelUtil<ProductSpecTemplateRelation> util = new ExcelUtil<ProductSpecTemplateRelation>(ProductSpecTemplateRelation.class);
        util.exportExcel(response, list, "模板与规格属性的关联数据");
    }

    /**
     * 获取模板与规格属性的关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplateRelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(productSpecTemplateRelationService.selectProductSpecTemplateRelationById(id));
    }

    /**
     * 新增模板与规格属性的关联
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplateRelation:add')")
    @Log(title = "模板与规格属性的关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductSpecTemplateRelation productSpecTemplateRelation) {
        return toAjax(productSpecTemplateRelationService.insertProductSpecTemplateRelation(productSpecTemplateRelation));
    }

    /**
     * 修改模板与规格属性的关联
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplateRelation:edit')")
    @Log(title = "模板与规格属性的关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductSpecTemplateRelation productSpecTemplateRelation) {
        return toAjax(productSpecTemplateRelationService.updateProductSpecTemplateRelation(productSpecTemplateRelation));
    }

    /**
     * 删除模板与规格属性的关联
     */
    @PreAuthorize("@ss.hasPermi('product:productSpecTemplateRelation:remove')")
    @Log(title = "模板与规格属性的关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(productSpecTemplateRelationService.deleteProductSpecTemplateRelationByIds(ids));
    }
}
